package com.niodata.dp.web.module.info;

import com.niodata.dp.core.usermgr.model.UserInfo;
import com.niodata.dp.web.module.base.BaseController;
import com.niodata.dp.web.security.ContextUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/info")
public class DpInfoController extends BaseController {

  @RequestMapping("build")
  @ResponseBody
  public Object getBuildInfo() {
    return BuildInfo.getInstance();
  }

  @RequestMapping("heartbeat")
  @ResponseBody
  public Object heartBeat() {
    UserInfo userInfo = ContextUtil.getCurrentUser();
    if (userInfo != null) {
      return userInfo.getUserName();
    } else {
      return "anonymous";
    }
  }
}
